<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib uri="/billing" prefix="b"%>
<%@page import="com.admin.service.ProvinceService"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>计费后台管理</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/managercss.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/wbox.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.form.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/wbox.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/validate.js"></script>
<script type="text/javascript">
<!--
	$(function(){
		$(".list div").mousemove(function(){
			$(this).css("background","#E3EEFF");
		}).mouseout(function(){
			$(this).css("background","");
		});
		$("#provinceId").val('${provinceId}');
		$("#isp").val('${isp}');
		$("#vodCustomized").val('${vodCustomized}');
	});

	function bd(spId,count){
		$.ajax({
			url:"<%=request.getContextPath()%>/admin/billingSp/join/${billingId}?",
			data:"spId="+spId+"&count="+count,
			type:"POST",
			success:function(flag){
				if(flag=='1'){
					alert("绑定成功!");
					window.location.href="<%=request.getContextPath()%>/admin/billingSp/${pageBean.url }&currentPage=${pageBean.currentPage}";
				}else{
					alert("绑定失败!");
				}
			}
		});
	}

	function del(id){
		if(confirm("你确认解除该绑定吗?")){
			$.ajax({
				url:"<%=request.getContextPath()%>/admin/billingSp/del/"+id,
				type:"GET",
				success:function(flag){
					if(flag=='1'){
						alert("解除成功!");
						window.location.href="<%=request.getContextPath()%>/admin/billingSp/${pageBean.url }&currentPage=${pageBean.currentPage}";
					}else{
						alert("解除失败!");
					}
				}
			});
		}
	}

	function goback(){
		window.location.href="<%=request.getContextPath()%>/admin/billingSp/hasjoin/${billingId}";
	}
//-->
</script>
</head>
<body>
<div class="information">
	<div class="search">
		<form action="<%=request.getContextPath() %>/admin/billingSp/${billingId}" method="post">
		<c:set value="<%=ProvinceService.getProvinceList() %>" var="provinceList"></c:set>
		省市：
		<select name="provinceId" id="provinceId" style="width: 120px;">
			<option value="">-----请选择-----</option>
			<c:forEach items="${provinceList}" var="p">
				<option value="${p.id }">${p.province }</option>
			</c:forEach>
		</select>
		运营商：
		<select name="isp" id="isp" style="width:120px;">
			<option value="">-----请选择-----</option>
			<option value="0">移动</option>
			<option value="1">联通</option>
		</select>
		计费类型：
		<select name="vodCustomized" id="vodCustomized" style="width:120px;">
			<option value="">-----请选择-----</option>
			<option value="0">点播</option>
			<option value="1">包月</option>
		</select>
		<input type="submit" value="查询">
		</form>
		
	</div>

	<div class="listTitle">
		<ul>
			<li style="width:40px;">编号</li>
			<li style="width:150px;">SP通道名</li>		
			<li style="width:60px;">端口</li>		
			<li style="width:60px;">指令</li>
			<li style="width:60px;">通道类型</li>
			<li style="width:60px;">资费</li>
			<li style="width:60px;">省份</li>
			<li style="width:60px;">运营商</li>
			<li style="width:150px;">操作</li>
		</ul>
		<div class="clear"></div>
	</div>

	<div class="list">
		<c:forEach items="${pageBean.result}" var="sp" varStatus="status">
			<div class="${status.index%2==0?'noselect':'select' }">
				<ul>
					<li style="width:40px;">${sp.spBean.spId }</li>
					<li style="width:150px;">${sp.spBean.spName }</li>	
					<li style="width:60px;">${sp.spBean.port }</li>		
					<li style="width:60px;">${sp.spBean.command }</li>
					<li style="width:60px;">
						<c:choose>
							<c:when test="${sp.spBean.vodCustomized==0 }">点播</c:when>
							<c:when test="${sp.spBean.vodCustomized==1 }">包月</c:when>
						</c:choose>
					</li>
					<li style="width:60px;">${sp.spBean.fee/10 }元</li>
					<li style="width:60px;"><b:province provinceId="${sp.spBean.provinceId }"/></li>
					<li style="width:60px;">
						<c:choose>
							<c:when test="${sp.spBean.isp==0 }">移动</c:when>
							<c:when test="${sp.spBean.isp==1 }">联通</c:when>
							<c:when test="${sp.spBean.isp==2 }">电信</c:when>
						</c:choose>
					</li>
					<li style="width:150px;">
						<c:choose>
							<c:when test="${not empty sp.billingSpBean}">
								<span style="color: red;font-weight: bold;">已绑定</span>
								<input type="button" value="解除" onclick="del('${sp.billingSpBean.id}')" />
							</c:when>
							<c:otherwise>
								<c:choose>
									<c:when test="${billing.fee%(sp.spBean.fee/10)==0 }">
										&nbsp;&nbsp;${billing.fee/(sp.spBean.fee/10)}条
										<input type="button" value="绑定" onclick="bd('${sp.spBean.spId }',${billing.fee/(sp.spBean.fee/10)});"/>
									</c:when>
									<c:otherwise>不能绑定</c:otherwise>
								</c:choose>
							</c:otherwise>
						</c:choose>
						
					</li>
				</ul>
				<div class="clear"></div>
			</div>
		</c:forEach>
	</div>
	<jsp:include page="../page.jsp" flush="true"></jsp:include>
	<div class="page"><input type="button" name="bd" value="查看已绑定的SP" onclick="goback()"></div>
</div>
</body>
</html>